import { Message } from 'element-ui'
import StringUtils from '@/utils/error/StringUtils'

export default {
  error(message) {
    this.isTrue(false, message)
  },
  trimHasLength(text, message) {
    this.isTrue(StringUtils.trimHasLength(text), message)
  },
  hasLength(text, message) {
    this.isTrue(StringUtils.hasLength(text), message)
  },
  notNull(val, message) {
    this.isTrue(!StringUtils.isEmpty(val), message)
  },
  isEmptyArray(array, message) {
    this.isTrue(!StringUtils.isEmptyArray(array), message)
  },
  isTrue(val, message) {
    if (!val) {
      throw Message(
        {
          message: message,
          type: 'error',
          duration: 3 * 1000
        }
      )
    }
  }
}
